<?php
namespace app\qihan\admin;
use app\admin\controller\Admin;
use app\qihan\model\QihanCategory;
use think\Db;

class Category extends QihanBase
{
	//列表页
    public function index()
    {
    	$_page = input('param.page/d', 0);
        $_keywords = input('param.keywords/s');
        $map = [];
        if ($_keywords) {
            $map['name'] = ['like', '%'.$_keywords.'%'];
        }
    	$data_list = Db::name('qihan_category')->where($map)->limit(50)->page($_page)->select();
    	$this->assign('data_list', $data_list);
        return $this->fetch();
    }
    //添加页
    public function edit()
    {
    	$id = input('param.id/d', 0);
        if ($this->request->isPost()) {
            $mod = new QihanCategory();
            if (!$mod->storage()) {
                return $this->error($mod->getError());
            }
            return $this->success('保存成功');
        }
        if($id){
        	$row = QihanCategory::where('id', $id)->find();
        	if(!$row){
        		return $this->error('数据不存在');
        	}
        	$this->assign('data_info', $row);
        }
        return $this->fetch('form');
    }
}